package co.yixiang.yshop.module.product.controller.admin.storeproductrelation;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.product.controller.admin.storeproductrelation.vo.StoreProductRelationPageReqVO;
import co.yixiang.yshop.module.product.controller.admin.storeproductrelation.vo.StoreProductRelationRespVO;
import co.yixiang.yshop.module.product.service.storeproductrelation.StoreProductRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 商品点赞和收藏")
@RestController
@RequestMapping("/product/store-product-relation")
@Validated
public class StoreProductRelationController {

    @Resource
    private StoreProductRelationService storeProductRelationService;


    @DeleteMapping("/delete")
    @Operation(summary = "删除商品点赞和收藏")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('product:store-product-relation:delete')")
    public CommonResult<Boolean> deleteStoreProductRelation(@RequestParam("id") Long id) {
        storeProductRelationService.deleteStoreProductRelation(id);
        return success(true);
    }


    @GetMapping("/page")
    @Operation(summary = "获得商品点赞和收藏分页")
    @PreAuthorize("@ss.hasPermission('product:store-product-relation:query')")
    public CommonResult<PageResult<StoreProductRelationRespVO>> getStoreProductRelationPage(@Valid StoreProductRelationPageReqVO pageVO) {
        PageResult<StoreProductRelationRespVO> pageResult = storeProductRelationService.getStoreProductRelationPage(pageVO);
        return success(pageResult);
    }

}
